package com.gdssoft.pdaweb.dao.water.impl;
/*
 *  捷达世软件（深圳）有限公司 地铁三号线考勤系统
 *  Copyright (C) 2008-2010 ShenZhen JieDaShi Software Limited Company.
*/
import java.util.ArrayList;
import java.util.List;

import com.gdssoft.core.Constants;
import com.gdssoft.core.dao.impl.BaseDaoImpl;
import com.gdssoft.pdaweb.dao.water.PdaWaterMeterDao;
import com.gdssoft.pdaweb.model.water.PdaWaterMeter;

@SuppressWarnings("unchecked")
public class PdaWaterMeterDaoImpl extends BaseDaoImpl<PdaWaterMeter> implements PdaWaterMeterDao{

	public PdaWaterMeterDaoImpl() {
		super(PdaWaterMeter.class);
	}
	
	@Override
	public List<PdaWaterMeter> getAllForExcel() {
		return findByHql("from PdaWaterMeter p where p.type=2");
	}

	@Override
	public PdaWaterMeter getByMeterId(String meterId) {
		List<PdaWaterMeter> list = new ArrayList<PdaWaterMeter>();
		try{
			list = findByHql("from PdaWaterMeter pm where pm.amId='"+meterId+"'");
		}catch(Exception e){
			logger.debug("PdaAmMeterList query error:"+e.getMessage());			
		}
		return list.size()>0?list.get(0):new PdaWaterMeter();
	}

	@Override
	public List<PdaWaterMeter> getByPosition(String districtId,String buildingId) {
		List<PdaWaterMeter> list = new ArrayList<PdaWaterMeter>();
		try{
			list = findByHql("from PdaWaterMeter pm where pm.isPlanned='"+Constants.UNPLANNED+"' and pm.districtId='"+districtId+"' and pm.buildingId='"+buildingId+"'");
		}catch(Exception e){
			logger.debug("PdaWaterMeter query error:"+e.getMessage());			
		}
		return list;
	}
	@Override
	public List<PdaWaterMeter> getByHouseId(String houseId){
		String hql = "from PdaWaterMeter pm where pm.aparmentId=?";
		return this.findByHql(hql,new String[]{houseId});
	}
	@Override
	public PdaWaterMeter getByBarcode(String barCode){
		String hql = "from PdaWaterMeter pm where pm.pdaMdAssetInfo.barCodebarCode=?";
		return (PdaWaterMeter) findUnique(hql, new String[]{barCode});
		
	}

	@Override
	public boolean isCrmMeterNoExist(String crmMeterNo) {
		//return findByHql("from PdaWaterMeter p where p.crmMeterNo=?",new Object[]{crmMeterNo}).size()>0;
		return false;
	}
}